package com.yami.shop.api.controller.app;

import com.yami.shop.bean.model.User;
import com.yami.shop.common.util.baidu.face.ImageBase64Converter;
import com.yami.shop.dao.UserMapper;
import com.yami.shop.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/p/user")
@Api(tags = "用户接口")
@AllArgsConstructor
public class FaceContlroller {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/getBizToken")
    @ApiOperation(value = "新人脸识别",notes = "新人脸识别")
        public ResponseEntity<String> getBizToken(){
            String userId = SecurityUtils.getUser().getUserId();
            User user = userMapper.selectById(userId);
            String[] base64 = new String[1];
            base64[0] = ImageBase64Converter.imgBase64(user.getIdentityPic());
            return ResponseEntity.ok(DetectAuth.getTok(base64));
        }

    @GetMapping("/getResult")
    @ApiOperation(value = "新人脸识别返回值",notes = "新人脸识别返回值")
        public ResponseEntity<String> getResult(String[] bizToken){
        GetDetectInfo.main(bizToken);
            return ResponseEntity.ok("验证结果已返回");
        }

}
